home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / mg2a_src.zip / DIR.C < prev    next >
C/C++ Source or Header  |  1988-08-23  |  1KB  |  60 lines

  1. /*
  2.  * Name:    MG 2a
  3.  *        Directory management functions
  4.  * Created:    Ron Flax (ron@vsedev.vse.com)
  5.  *        Modified for MG 2a by Mic Kaczmarczik 03-Aug-1987
  6.  */
  7.  
  8. #include "def.h"
  9.  
  10. #ifndef NO_DIR
  11. #ifndef    getwd            /* may be a #define */
  12. char    *getwd();
  13. #endif
  14. char    *wdir;
  15. static char cwd[NFILEN];
  16.  
  17. /*
  18.  * Initialize anything the directory management routines need
  19.  */
  20. dirinit()
  21. {
  22.     if (!(wdir = getwd(cwd)))
  23.         panic("Can't get current directory!");
  24. }
  25.  
  26. /*
  27.  * Change current working directory
  28.  */
  29. /*ARGSUSED*/
  30. changedir(f, n)
  31. {
  32.     register int s;
  33.     char bufc[NPAT];
  34.  
  35.     if ((s=ereply("Change default directory: ", bufc, NPAT)) != TRUE)
  36.         return(s);
  37.     if (bufc[0] == '\0')
  38.         (VOID) strcpy(bufc, wdir);
  39.     if (chdir(bufc) == -1) {
  40.         ewprintf("Can't change dir to %s", bufc);
  41.         return(FALSE);
  42.     } else {
  43.         if (!(wdir = getwd(cwd)))
  44.             panic("Can't get current directory!");
  45.         ewprintf("Current directory is now %s", wdir);
  46.         return(TRUE);
  47.     }
  48. }
  49.  
  50. /*
  51.  * Show current directory
  52.  */
  53. /*ARGSUSED*/
  54. showcwdir(f, n)
  55. {
  56.     ewprintf("Current directory: %s", wdir);
  57.     return(TRUE);
  58. }
  59. #endif
  60.